package com.example.tnot.Teacher.CoursePart.CourseInternal.CourseDetailHome.Live.HistoryMeet.Adapter;

import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.tnot.R;
import com.example.tnot.Teacher.CoursePart.CourseInternal.CourseDetailHome.Live.HistoryMeet.ItemBean.History;
import com.example.tnot.Util.ToastUtil;

import java.util.List;

public class rv_live_historyAdapter extends RecyclerView.Adapter<rv_live_historyAdapter.ViewHolder>{
    private List<History> historyList;
    public rv_live_historyAdapter(List<History> historyList) {
        this.historyList = historyList;
    }

    @NonNull
    @Override
    public rv_live_historyAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_history_meet,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull rv_live_historyAdapter.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
        holder.tv_meeting_name.setText(historyList.get(position).getMeeting_name());
        holder.tv_meeting_number.setText(historyList.get(position).getMeeting_number());
        holder.tv_meeting_time.setText(historyList.get(position).getMeeting_time());
        holder.tv_meeting_organizer.setText(historyList.get(position).getMeeting_organizer());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtil.showCustomToast(v.getContext(),"点击了"+historyList.get(position).getMeeting_name());
            }
        });
    }

    @Override
    public int getItemCount() {
        return historyList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        TextView tv_meeting_number,tv_meeting_name,tv_meeting_time,tv_meeting_organizer;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_meeting_number = itemView.findViewById(R.id.tv_meeting_number);
            tv_meeting_name = itemView.findViewById(R.id.tv_meeting_name);
            tv_meeting_time = itemView.findViewById(R.id.tv_meeting_time);
            tv_meeting_organizer = itemView.findViewById(R.id.tv_meeting_organizer);
        }
    }
    public void updateList(List<History> newList) {
        this.historyList = newList;
        notifyDataSetChanged();
    }
}
